package org.grow.support.config;

import org.grow.support.data.SimpleRedisDs;
import org.grow.support.service.CodeGene;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.awt.*;

/**
 * @Author: xwg
 * @CreateDate: 2022/2/10
 */

@Configuration
@ConditionalOnClass(StringRedisTemplate.class)
@EnableConfigurationProperties(SimpleRedisDs.class)
public class CodeConfig {
    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    @ConditionalOnMissingBean
    public ThreadLocal<CodeGene> codeGeneThreadLocal(StringRedisTemplate stringRedisTemplate) {
//        return ThreadLocal.withInitial(() -> applicationContext.getBean(CodeGene.class));
        return ThreadLocal.withInitial(() -> {
            CodeGene codeGene = new CodeGene();
            codeGene.setStringRedisTemplate(stringRedisTemplate);
            return codeGene;
        });
    }
    @Bean
    public Point point(){
        return  new Point(101,202);
    }


}
